#ifndef FRAMEBUFFER_H
#define FRAMEBUFFER_H

#include <QImage>
#include <QRect>
#include <QColor>
#include <QList>
#include <QMutex>

class FrameBuffer
{
public:
    explicit FrameBuffer(int width = 1920, int height = 1080);
    ~FrameBuffer();
    
    // 图像操作
    void resize(int width, int height);
    void fill(const QColor &color);
    void updateRegion(const QImage &image, const QRect &region);
    void updateRegions(const QList<QImage> &images, const QList<QRect> &regions);
    
    // 获取图像
    const QImage& getImage() const;
    QImage getImage(const QRect &region) const;
    
    // 增量更新支持
    QList<QRect> getUpdatedRegions();
    void clearUpdatedRegions();
    
    // 属性获取
    int getWidth() const;
    int getHeight() const;
    QSize getSize() const;
    bool isEmpty() const;

private:
    QImage image;
    int width;
    int height;
    mutable QMutex mutex;
    QList<QRect> updatedRegions;
    bool hasUpdates;
};

#endif // FRAMEBUFFER_H